package com.cc.Dao.Impl;

import com.cc.Dao.BaseDao;
import com.cc.Dao.MeetingRoomDao;
import com.cc.entity.MeetingRoom;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

//实现会议Dao层抽象方法
public class MeetingRoomDaoImpl extends BaseDao implements MeetingRoomDao {


    //实现集合列表(查询方法) 静态查询
    @Override
    public List<MeetingRoom> queryMeetingRoom() {
        List<MeetingRoom> meetingRooms = new ArrayList<>();
        String sql = "select * from meeting_room";
        ResultSet rs = executeQuery(sql,null);
        if (rs != null) {
            try {
                while (rs.next()){
                    MeetingRoom meetingRoom = new MeetingRoom();
                    meetingRoom.setRoom_id(rs.getInt("room_id"));
                    meetingRoom.setRoom_name(rs.getString("room_name"));
                    meetingRoom.setCapacity(rs.getString("capacity"));
                    meetingRoom.setDepartment(rs.getString("department"));
                    meetingRoom.setAddress(rs.getString("address"));
                    meetingRoom.setStatus(rs.getInt("status"));
                    meetingRooms.add(meetingRoom);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                close(rs);
            }
        }

        return meetingRooms;
    }

    //实现添加会议方法()
    @Override
    public int addMeetingRoom(MeetingRoom meetingRoom) {
        String sql = "INSERT INTO meeting_room (room_name,capacity,department,address,`status`) VALUES (?,?,?,?,?)";
        Object[] params = {meetingRoom.getRoom_name(), meetingRoom.getCapacity(), meetingRoom.getDepartment(),meetingRoom.getAddress(),meetingRoom.getStatus()
        };
        return executeUpdate(sql, params);
    }

    //实现删除会议方法()
    @Override
    public boolean delMeetingRoom(String id) {
        String sql = "DELETE FROM meeting_room WHERE room_id=?";
        Object[] params = {id};
        return executeUpdate(sql,params) == 1;
    }
}
